/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
#ifndef DEVMON_H
#define DEVMON_H

#include <mc/engine.h>
#include <mc/reflect.h>

#include "discovery/object_group.h"
#include "discovery/root_object.h"
#include "topology/device_topo.h"
#include "topology/root_topo_object.h"
#include "topology/topology_discovery.h"

namespace devmon {

namespace po = boost::program_options;

struct devmon_config {
    MC_REFLECTABLE("DevmonConfig")

    std::string                                  driver_path;
    std::unordered_map<std::string, std::string> app_paths;
};

/**
 * @brief 设备管理器服务类
 */
class devmon_service : public mc::engine::service {
public:
    devmon_service(const std::string& name) : mc::engine::service(name) {
    }

    bool init(mc::dict args) override;
    bool start() override;
    bool stop() override;
    void cleanup() override;
    void on_dump(std::map<std::string, std::string> context, std::string file_path) override;
    void dump_scanners_info(std::string file_path);
    void dump_accessors_info(std::string file_path);
    void dump_chips_access_info(std::string file_path);
    void dump_drivers_load_info(std::string file_path);

    struct register_options {
        void operator()(po::options_description& cli_opts, po::options_description& cfg_opts) {
            cfg_opts.add_options()("devmon.driver_path",
                                   po::value<std::string>()->default_value("./drivers"),
                                   "devmon driver path");
        }
    };

private:
    root_object_ptr      m_root_object;
    root_topo_object_ptr m_root_topo_object;
};

} // namespace devmon

#endif // DEVMON_H